﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DAL;
using System.Data.Linq;
using DAL._4_RepositoryImplement;
using BLL;
using System.Diagnostics;

namespace LinqToSql加入IUnitOfWork.Controllers
{
    public class HomeController : Controller
    {
        OrderManager orderManager;

        public HomeController()
        {
            orderManager = new OrderManager();

        }
        public ActionResult Index()
        {
            #region 实体赋值
            Order_Info entity = new Order_Info
            {
                CreateDate = DateTime.Now,
                UserID = 1,
                Order_Detail = new EntitySet<Order_Detail>
                {
                    new Order_Detail
                    {
                      ProductID=1,
                      ProductName="香蕉1"
                    },
                     new Order_Detail 
                    {
                      ProductID=2,
                      ProductName="香蕉2"
                    }
                }
            };
            Product product = new Product
            {
                CreateDate = DateTime.Now,
                ProductName = "ok",
            };
            #endregion

            orderManager.GeneratorOrder(entity, product);
            var model = orderManager.GetOrder();
            return View(model);
        }

        public ActionResult CreateOrder()
        {

            return View();
        }

        [HttpPost]
        public ActionResult CreateOrder(Order_Info order_info)
        {
            orderManager.GeneratorOrder(order_info);
            return View();
        }

        public ActionResult ProductIndex()
        {
            Stopwatch sw = new Stopwatch();
            sw.Restart();
            var model = orderManager.GetProduct(); //speed:51
            //  var model = orderManager.GetProductThread();//speed:74
            sw.Stop();
            ViewData["speed"] = sw.ElapsedMilliseconds;
            return View(model);
        }
    }
}
